package com.huilian.iotbox.admin.controller;

import com.huilian.iotbox.admin.service.RolePermissionService;
import com.huilian.iotbox.admin.service.UserService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.controller.BaseController;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 少凡
 * @date 2020/3/8 9:01
 */
@RestController
@RequestMapping("/api/rolePermission")
public class RolePermissionController extends BaseController {

    @Autowired
    private RolePermissionService rolePermissionService;

    @Autowired
    private UserService userService;


    @PostMapping("/authorize")
    public ServerResponse authorize(HttpServletRequest request,
                                    @RequestBody List<Integer> newPermissionIdList, Integer roleId,
                                    @RequestParam(required = true) Integer platformType) {

        UserInfo userInfo = userService.getLoginUserInfo(request);

        return rolePermissionService.authorizeBatch(newPermissionIdList, roleId, userInfo,platformType);
    }
}
